﻿@using System.Web.WebPages.Scope;

@helper AddMetaTagsAndEvents() {
    
    <meta name="application-name" content="@ApplicationName" />
    <meta name="msapplication-tooltip" content="@ApplicationName" />
    
    <meta name="msapplication-starturl" content="./" />
    <meta name="msapplication-navbutton-color" content="@ApplicationColor" />
    <meta name="msapplication-window" content="width=800;height=600"/>
    
    <script type="text/javascript">
        $(document).ready(function(){
            
            $('.ie9AddOverlay').click(function(){
                window.external.msSiteModeSetIconOverlay($(this).attr("data-overlay"), "My Overlay");
            });
            
            $('.ie9ClearOverlay').click(function(){
                window.external.msSiteModeClearIconOverlay();   
            });
            
            $('.ie9WindowActivate').click(function(){
                window.external.msSiteModeActivate();
            });
            
            $('.ie9AddToStart').click(function(){
                window.external.msAddSiteMode(); 
            });
        });
    </script>   
}

@helper AddJumpLists () {
    
    //loop
    if ( IsInitialized ) {
        foreach ( var item in JumplistItems )
        {
            <meta name="msapplication-task" content="name=@item.Name;action-uri=@item.Action;icon-uri=@item.Icon" />
        }
    }
}

@functions {

    private static readonly object _isInitializedKey = new object();
    private static readonly object _applicaitonName = new object();
    private static readonly object _applicaitonColor = new object();
    private static readonly List<dynamic> _jumplistItems = new List<dynamic>(); 

    /// <summary>
    /// Initialization property. Returns if the instance is initialized within the current scopestorage
    /// </summary>
    public static bool IsInitialized {
        get {
            return (bool) (ScopeStorage.CurrentScope[_isInitializedKey] ?? false);
        }        
        private set {
            ScopeStorage.CurrentScope[_isInitializedKey] = value;
        }
    }
    
     public static void Initialize(string applicationName, string applicationColor, List<dynamic> jumplistItems) {
        
        ApplicationName = applicationName;
        ApplicationColor = applicationColor;
        JumplistItems = jumplistItems;

        if ( !applicationName.IsEmpty() ) {
            IsInitialized = true;
        }
    }
    
    private static string ApplicationName {
        get {
            return (string) (ScopeStorage.CurrentScope[_applicaitonName] ?? "");
        }        
        set {
            ScopeStorage.CurrentScope[_applicaitonName] = value;
        }
    }
    
    private static string ApplicationColor {
        get {
            return (string) (ScopeStorage.CurrentScope[_applicaitonColor] ?? "");
        }        
        set {
            ScopeStorage.CurrentScope[_applicaitonColor] = value;
        }
    }
    
    private static List<dynamic> JumplistItems {
        get {
            return (List<dynamic>) (ScopeStorage.CurrentScope[_jumplistItems] ?? "");
        }        
        set {
            ScopeStorage.CurrentScope[_jumplistItems] = value;
        }
    }
    
}